package com.yuanfeng.gateway.config;


import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @author Stranger
 * @date 2023/4/24 15:03
 */
@Configuration
public class GatewayResolver {
    @Bean("keyResolver")
    public KeyResolver hostAddrKeyResolver() {
        return exchange -> {
            String ip = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
            return Mono.just(ip);
        };
    }
}
